/*

package com.walter.learn.UseThread;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.Stack;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;


*/
/**
 * @ProjectName: learnOwner
 * @Package: com.walter.learn.UseThread
 * @ClassName: TestThreadPoolBySYP
 * @Description: java类作用描述
 * @Author: 唐朝
 * @CreateDate: 2019/2/18 16:14
 * @UpdateUser: 更新者
 * @UpdateDate: 2019/2/18 16:14
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 *//*


public class TestThreadPoolBySYP {
    static Connection conn = null;
    static Stack<String> list = new Stack<>();
    static String markId = "0";

    public static void main(String[] args) throws InterruptedException, SQLException {


        Runner runner = new Runner();
        Runner1 runner1 = new Runner1();

        ExecutorService pool = Executors.newCachedThreadPool();
        // 创建线程
        Thread thread1 = new Thread(runner1);
        pool.execute(thread1);
        for (int i = 0; i < 50; i++) {
            Thread thread = new Thread(runner);
            // 将线程放入池中进行执行
            pool.execute(thread);
        }
        // 关闭线程池
        //pool.shutdown();
        ////////////////////////////////
//        String container = "2017-07-25";
//        String objName = "4710332-102-009-1522.mp4";
//        Map map = JCloudsNewSwiftApi.getJCswift().getHeaderStatus(container, objName);
//        System.out.println(map);
//
//        String newContainer = "2018-12-26";
//        String newObjName = "p6738402-102-009-111425.mp4";
//        Map map1 = JCloudsNewerSwiftApi.getJCswift().getHeaderStatus(newContainer, newObjName);
//        System.out.println(map1);
    }

    static class Runner implements Runnable {
        public void run() {
            for (; ; ) {
                if (list.size() < 1) {
                    try {
                        System.out.println(Thread.currentThread().getName() + ":等待:::" + list.size());
                        Thread.sleep(2000);
                        if (list.size() < 1) {
                            Thread.sleep(10000);
                            if (list.size() < 1) {
                                wait();
                            }
                        }
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                } else {

                    System.out.println(list.size());
                    th(list.pop());
                }
            }
        }
    }

    static class Runner1 implements Runnable {
        public void run() {
            for (; ; ) {
                if (list.size() < 200) {
                    try {
                        list = getUrlList(list);
                        if (list.size() < 1) {
                            wait();
                        }
                    } catch (SQLException e) {
                        System.out.println("获取失败");
                        e.printStackTrace();
                    } catch (InterruptedException e) {
                        System.out.println("数据以取尽");
                        e.printStackTrace();
                    }
                } else {
                    try {
                        System.out.println(Thread.currentThread().getName() + ":获取数据:::" + list.size());
                        Thread.sleep(10000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }


    public static Connection getconn() throws SQLException {

        String sql = "";

        String url = "jdbc:mysql://local.db.cmpp.ifengidc.com:3306/v_ifeng?useSSL=false&serverTimezone=GMT";
        String user = "cmppdev";
        String pwd = "cmppdevifengifeng";
        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();// 动态加载mysql驱动
            //System.out.println("成功加载MySQL驱动程序");

            // 一个Connection代表一个数据库连接
            if (conn == null)
                conn = DriverManager.getConnection(url, user, pwd);

        } catch (SQLException e) {
            System.out.println("MySQL操作错误");
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {

        }
        return conn;
    }

    public static void th(String str) {
        //String str = list.pop();
        String id = str.split("@_@")[0];
        String guid = str.split("@_@")[1];
        String publishTime = str.split("@_@")[2];
        String mediaFiles = str.split("@_@")[3];
        String statuser = str.split("@_@")[4];
        String vname = "";
        //String vurl = "";
        JSONArray jsonArray = JSONArray.parseArray(mediaFiles);
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject item = jsonArray.getJSONObject(i);
            if (item.getString("mediaType").equals("mp4")) {
                String e = item.getString("videoPlayUrl");
                vname = e.substring(e.lastIndexOf("/") + 1);
                //publishTime = vurl.split("/")[0]+"-"+vurl.split("/")[1]+"-"+vurl.split("/")[2];
                //vname = vurl.split("/")[3];
                //System.out.println(vname);
                sys(str, publishTime, vname, guid, id);
            }
        }

    }

    public static void sys(String str, String publishTime, String vname, String guid, String id) {
        System.out.println(str + ":::::\r\n" + list.size());
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date temp = null;
        Date time = null;
        try {
            temp = sdf.parse("2018-06-25");
            time = sdf.parse(publishTime);
        } catch (ParseException e) {
            System.out.println("时间格式");
            e.printStackTrace();
        }
        Map map = null;

        //早于2018-06-25
        System.out.println("================>markId::::" + markId);
        if (time.before(temp)) {
            System.out.println(sdf.format(time) + "++" + vname);

            map = JCloudsNewSwiftApi.getJCswift().getHeaderStatus(sdf.format(time), vname);
        } else {
            System.out.println(sdf.format(time) + "++" + vname);
            map = JCloudsNewerSwiftApi.getJCswift().getHeaderStatus(sdf.format(time), vname);
        }
        System.out.println(map);
        try {
            if (map != null) {
                if (map.size() == 0) {
                    System.out.println("视频是上线状态");
                } else {
                    Object status = map.get("status");
                    if (status == null || "1".equals(status)) {
                        System.out.println("视频是上线状态");
                    } else if ("0".equals(status)) {
                        //out(id, guid, publishTime, vname, "审核");
                        System.out.println("视频是审核状态");
                    } else if ("-1".equals(status)) {
                        //out(id, guid, publishTime, vname, "下线");
                        System.out.println("视频是下线状态");
                    }
                }
            } else {
                //out(id, guid, publishTime, vname, "未找到");
                System.out.println("视频不存在");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void out(String id, String guid, String vid, String title, String categoryId) throws Exception {
        //Connection conn = getconn();
        String sql = "";
        try {
            String insertSql = "insert into frm_30419(categoryName,guid,vid,title,categoryId) values(?,?,?,?,?)"; // maxid 3250870（mp3）  3277441（mp4）
            mysqlHelper1.executeNonQuery(insertSql, id, guid, vid, title, categoryId);

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    ////////////////////
    public static Stack<String> getUrlList(Stack<String> list) throws SQLException {
        //Stack<String> list = new Stack<>();
        Connection conn = getconn();
        String sql = "";
        Statement stmt = conn.createStatement();
        sql = "select id,guid,publishTime,mediaFiles,status from frm_323 force index(id)  where id>" + markId + " and status=1 order by id limit 1000";
        ResultSet result = stmt.executeQuery(sql);
        if (result != null) {
            while (result.next()) {
//                    model.setId(result.getString("id"));
//                    model.setGuid(result.getString("guid"));
//                    model.setPublishTime(result.getString("publishTime"));
//                    model.setSrcVideo(result.getString("srcVideo"));
//                    model.setStatus(result.getString("status"));
                if (result.getString("status").equals("1")) {
                    list.push(result.getString("id") + "@_@" +
                            result.getString("guid") + "@_@" +
                            result.getString("publishTime") + "@_@" +
                            result.getString("mediaFiles") + "@_@" +
                            result.getString("status"));
                }
                markId = result.getString("id");
            }
        }
        return list;
    }
}
*/
